<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="140px">
      <el-form-item label="审核人员名字" prop="examineAdminName">
        <el-input
          v-model="queryParams.examineAdminName"
          placeholder="请输入审核人员姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="被审核人姓名" prop="examineUserName">
        <el-input
          v-model="queryParams.examineUserName"
          placeholder="请输入被审核人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="被审核人员类型" prop="userType">
        <el-select v-model="queryParams.userType" placeholder="请选择被审核人员类型" clearable size="small">
          <el-option label="研究生" :value="1" />
          <el-option label="导师" :value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="审核信息是否已查阅" prop="isSuccess">
        <el-select v-model="queryParams.isSuccess" placeholder="审核信息是否已查阅" clearable size="small">
          <el-option label="未查阅" :value="0" />
          <el-option label="已查阅" :value="1" />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="审核信息" prop="message">-->
<!--        <el-input-->
<!--          v-model="queryParams.message"-->
<!--          placeholder="请输入审核信息"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建时间" prop="createDate" >-->
<!--        <el-date-picker clearable size="small"-->
<!--          v-model="queryParams.createDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="选择创建时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="修改时间" prop="updateDate" >-->
<!--        <el-date-picker clearable size="small"-->
<!--          v-model="queryParams.updateDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="选择修改时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item style="margin-left: 70px;">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['mentor:examine:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['mentor:examine:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mentor:examine:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mentor:examine:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="examineList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" v-if="false"/>
      <el-table-column label="审核人员名字" align="center" prop="examineAdminName" />
      <el-table-column label="被审核人姓名" align="center" prop="examineUserName" />
      <el-table-column label="被审核人员类型 1,研究生 2导师" align="center" prop="userType" >
        <template slot-scope="scope">
          <el-tag type="primary" v-if="scope.row.userType==1">研究生</el-tag>
          <el-tag type="warning" v-if="scope.row.userType==2">导师</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核是否已被查阅" align="center" prop="isSuccess">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.isSuccess==1">已查阅</el-tag>
          <el-tag type="danger" v-if="scope.row.isSuccess==0">未查阅</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核信息" align="center" prop="message" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="updateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="逻辑删除" align="center" prop="isDeleted" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['mentor:examine:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mentor:examine:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改审核信息对话框 -->
<!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>-->
<!--      <el-form ref="form" :model="form" :rules="rules" label-width="80px">-->
<!--        <el-form-item label="审核人员名字" prop="examineAdminName">-->
<!--          <el-input v-model="form.examineAdminName" placeholder="请输入审核人员名字" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="被审核人姓名" prop="examineUserName">-->
<!--          <el-input v-model="form.examineUserName" placeholder="请输入被审核人姓名" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="被审核人员类型 1,研究生 2导师" prop="userType">-->
<!--          <el-select v-model="queryParams.userType" placeholder="请选择被审核人员类型" clearable size="small">-->
<!--            <el-option label="研究生" :value="1" />-->
<!--            <el-option label="导师" :value="2" />-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="审核是否被查阅" prop="isSuccess">-->
<!--          <el-select v-model="queryParams.isSuccess" placeholder="审核是否被查阅" clearable size="small">-->
<!--            <el-option label="已查阅" :value="1" />-->
<!--            <el-option label="未查阅" :value="0" />-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="审核信息" prop="message">-->
<!--          <el-input v-model="form.message" placeholder="请输入审核信息" />-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--        <el-button @click="cancel">取 消</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->
  </div>
</template>

<script>
import { listExamine, getExamine, delExamine, addExamine, updateExamine, exportExamine } from "@/api/mentor/examine";

export default {
  name: "Examine",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 审核信息表格数据
      examineList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examineAdminName: undefined,
        examineUserName: undefined,
        userType: undefined,
        isSuccess: undefined,
        message: undefined,
        createDate: undefined,
        updateDate: undefined,
        isDeleted: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createDate: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateDate: [
          { required: true, message: "修改时间不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询审核信息列表 */
    getList() {
      this.loading = true;
      listExamine(this.queryParams).then(response => {
        this.examineList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        examineAdminName: undefined,
        examineUserName: undefined,
        userType: undefined,
        isSuccess: undefined,
        message: undefined,
        createDate: undefined,
        updateDate: undefined,
        isDeleted: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加审核信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getExamine(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改审核信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateExamine(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addExamine(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除审核信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delExamine(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有审核信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportExamine(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
